import React from 'react';
import { Button, ButtonProps } from "antd";

import { withModal, mountModal } from "@yaf/pro-ui";
import CreateOrEdit from './CreateOrEdit';
import { RespDataType } from "../../../api";

interface CreateOrEditBtnProps extends ButtonProps {
  deptId?: number;
  optType: "add" | "edit";
  fetchList: () => void;
  editData?: RespDataType.DeptItem,
}

const CreateOrEditBtn: React.FC<CreateOrEditBtnProps> = ({ deptId, optType, fetchList, editData, ...restProps }) => {
  return <Button
    onClick={() => {
      const CreateOrEditModal = withModal(CreateOrEdit);
      mountModal(<CreateOrEditModal
        modalProps={{
          title: `${optType == "add" ? "添加" : "编辑"}组织`,
          width: "50%",
        }}
        optType={optType}
        deptId={deptId}
        fetchList={fetchList}
        editData={editData}
      />)
    }}
    {...restProps}
  />
};

export default CreateOrEditBtn;
